<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 2017/5/30
 * Time: 2:04
 */
header("Access-control-allow-origin:*");//允许跨域

if(!empty($_POST)&&$_POST["loginname"]&&$_POST["loginpwd"]);

//获取数据库的ip配置
$dbserver="127.0.0.1";
$dbuser="root";
$dbpwd="";
$database="tiangou";


//创建连接
$connection=new mysqli($dbserver,$dbuser,$dbpwd,$database);

//配置一个连接的字符集
mysqli_query($connection, "set names utf8");//给的$connection的字符串设置字符集

//sql语句   查询
$sql="SELECT*FROM userinfo WHERE uname='".$_POST["loginname"]."' AND upwd='".$_POST["loginpwd"]."'";

//返回结果
$result=$connection->query($sql);

//print_r($result); //打印结果有num_rows=>1

if($result->num_rows==1){
    //使用关联数组
    $arr=array("status"=>1,"msg"=>"登录成功");
    print_r(json_encode($arr));
}else{
    $arr=array("status"=>0,"msg"=>"用户名或密码错误，请重新登录");
    print_r(json_encode($arr));
}
//关闭连接

$connection->close();